#include common_scripts\utility;
#include maps\mp\_utility;
#include maps\mp\gametypes\_hud_util;


init()
{
}

startSoulSelecting()
{
    self endon("death");
    self endon("disconnect");
    
    self hide();
    self freezeControlsWrapper(true);
    self setBlurForPlayer(4.5, 0.5);
    
    self.z_MenuIsSelectingSoul = true;
    
    self z_mod\_hud::showHUD_SoulSelect();
    
    self.z_HUDSoulSelect.shader = level.z_Souls[self.z_SoulWanted].img;
    self.z_HUDSoulSelect setShader(self.z_HUDSoulSelect.shader, 120, 24);
    self.z_HUDSoulSelectText setText(level.z_Souls[self.z_SoulWanted].name);
    
    while(self.z_MenuIsSelectingSoul) {
        act = self waittill_any_return("zkey_activate", "zkey_back", "zkey_forward");
        
        if(act == "zkey_back") {
            self.z_SoulWanted++;
            
            if(self.z_SoulWanted >= level.z_Souls.size)
                self.z_SoulWanted = 0;
            
            self.z_HUDSoulSelect.shader = level.z_Souls[self.z_SoulWanted].img;
            self.z_HUDSoulSelect setShader(self.z_HUDSoulSelect.shader, 120, 24);
            self.z_HUDSoulSelectText setText(level.z_Souls[self.z_SoulWanted].name);
        } else if(act == "zkey_forward") {
            self.z_SoulWanted--;
            
            if(self.z_SoulWanted < 0)
                self.z_SoulWanted = level.z_Souls.size-1;
            
            self.z_HUDSoulSelect.shader = level.z_Souls[self.z_SoulWanted].img;
            self.z_HUDSoulSelect setShader(self.z_HUDSoulSelect.shader, 120, 24);
            self.z_HUDSoulSelectText setText(level.z_Souls[self.z_SoulWanted].name);
        } else if(act == "zkey_activate") {
            if(isDefined(level.z_Souls[self.z_SoulWanted].player) && getDvarInt("z_UniqueSouls")) {
                self iPrintLnBold(level.z_Souls[self.z_SoulWanted].name + " is ^1busy^7 by " + level.z_Souls[self.z_SoulWanted].player.name);
            } else {
                self.z_SoulCurrent = self.z_SoulWanted;
                self.z_SoulExp = 0;
                
                level.z_Souls[self.z_SoulCurrent].player = self;
                
                self z_mod\_souls::giveSoul();
                
                self.z_MenuIsSelectingSoul = false;
            }
        }
    }
    
    self setBlurForPlayer(0.0, 1.5);
    self freezeControlsWrapper(false);
    self show();
    
    self z_mod\_hud::hideHUD_SoulSelect();
}

